#include<bits/stdc++.h>
using namespace std;
const int N = 21;
struct di{
	int m;
	int next;
}d[N];
int a[N];
int v[N][N];
int main(){
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>a[i];
		d[i].m = a[i];
	}
	for(int i = 1;i<n;i++){
		for(int j = i+1;j<=n;j++){
			cin>>v[i][j];
		}
	}
	for(int i = n-1;i>0;i--){
		for(int j = i+1;j<=n;j++){
			if(v[i][j]==0)continue;
			if(d[i].m < d[j].m + a[i]){
				d[i].m = d[j].m + a[i];
				d[i].next = j;
			}
		}
	}
	int ans = 0;
	int k = 0;
	for(int i = 1;i<=n;i++){
		if(d[i].m > ans){
			ans = d[i].m;
			k = i;
		}
	}
	while(k!=0){
		cout<<k<<" ";
		k = d[k].next;
	}
	cout<<endl;
	cout<<ans;
	return 0;
}
